package openjdk.jdk8;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;


/**
 * 由DateTimeFormatter的静态方法ofPattern()构建日期格式，LocalDateTime和LocalDate等一些表示日期或时间的类使用parse和
 * format方法把日期和字符串做转换。
 *
 * 使用新的API，整个转换过程都不需要考虑线程安全的问题。
 *
 */
public strictfp class DatetimeFormatter {
    public static void main(String[] args) {
        String dateStr= "2016年10月25日";
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日");
        LocalDate date= LocalDate.parse(dateStr, formatter);

        System.out.printf("localdate is : %s\n",date);

        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy年MM月dd日 hh:mm a");
        String nowStr = now .format(format);
        System.out.printf("Local datetime is : %s\n",nowStr);

        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
        nowStr = now.format(fmt);
        System.out.printf("Local datetime is : %s\n",nowStr);

        float aFloat = 0.6710339f;
        double aDouble = 0.04150553411984792d;

        double sum = aFloat + aDouble;
        float quotient = (float)(aFloat / aDouble);
        System.out.println("float: " + aFloat);
        System.out.println("double: " + aDouble);
        System.out.println("sum: " + sum);
        System.out.println("quotient: " + quotient);
    }
}
